<?php

//具体公司类(组合类)
class ConcreteCompany extends Company
{
    private $company_list;
    private $name;

    public function __construct($name)
    {
        $this->name = $name;
    }

    public function add(Company $company)
    {
        $this->company_list[] = $company;
    }

    public function remove(Company $company)
    {
        $index = array_search($company, $this->company_list);
        if ($index !== false) {
            unset($this->company_list[$index]);
        }
    }

    public function display($depth)
    {
        fwrite(STDOUT, str_repeat('-', $depth) . $this->name . "\n");

        if (!$this->company_list) {
            return;
        }
        $depth++;
        foreach ($this->company_list as $company) {
            $company->display($depth);
        }
    }

    public function lineOfDuty()
    {
        foreach ($this->company_list as $company) {
            $company->lineOfDuty();
        }
    }
}